#ifndef _boot_H
#define _boot_H

#include "stdint.h"

#define GD32_FLASH_SADDR      ((uint32_t)(0x08000000))
#define GD32_PAGE_SIZE         1024
#define GD32_PAGE_NUM					 8
#define GD32_B_PAGE_NUM				 3
#define GD32_A_PAGE_NUM    GD32_PAGE_NUM-GD32_B_PAGE_NUM
#define GD32_A_START_PAGE  GD32_B_PAGE_NUM
#define GD32_A_SADDR       GD32_FLASH_SADDR + GD32_A_START_PAGE*128* GD32_PAGE_SIZE

#define UPDATA_A_FLASH	 	0X00000001
#define IAP_XMODEMC_FLAG	0X00000002
#define IAP_XMODEMD_FLAG	0X00000004
#define IAP_VERSION_FLAG	0X00000008
#define CMD_5_FLAG				0X00000010
#define CMD5_XMODEM_FLAG 	0X00000020
#define CMD_6_FLAG 				0X00000040

#define OTA_SET_FLAG  		0xAABB1122
typedef struct 
{
		uint32_t OTA_flag;
		uint32_t Firelen[11];
		uint8_t  OTA_ver[32];
}OTA_InfoCB;
#define OTA_INFOCB_SIZE sizeof(OTA_InfoCB)
	

typedef struct 
{
		uint8_t Updatabuff[GD32_PAGE_SIZE];
		uint32_t W25Q64_BlockNB;
		uint32_t XmodemTimer;
		uint32_t XmodemNB;
		uint32_t XmodemCRC;
}UpDatA_CB;


extern OTA_InfoCB OTA_Info;
extern UpDatA_CB UpDataA;
extern uint32_t BootStaFlag;

typedef void (*pFucntion)(void);

void LOAD_A(uint32_t addr);
void BootLoader_Brance(void);
void BootLoader_Clear(void);
void BootLoader_Info(void);
uint8_t BootLoader_Enter(uint8_t timeout);
void BootLoader_Event(uint8_t *data, uint16_t  datalen);
uint16_t Xmodem_CRC16(uint8_t *data,uint16_t datalen) ;

#endif

